﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Littlebeer.Deduplicate.Models
{
    /// <summary>
    /// 查重规则类
    /// </summary>
    public class DeduplicateRule
    {
        /// <summary>
        /// 规则类型，如系统自动（规则定义比较严谨，无需人工再确认），人工确认
        /// </summary>
        private DeduplicateRuleType _RuleType;

        public DeduplicateRuleType RuleType
        {
            get { return _RuleType; }
            set { _RuleType = value; }
        }

        /// <summary>
        /// 规则涉及的字段列表
        /// </summary>
        private List<DeduplicateRuleField> _DeduplicateRuleFields;

        public List<DeduplicateRuleField> DeduplicateRuleFields
        {
            get { return _DeduplicateRuleFields; }
            set { _DeduplicateRuleFields = value; }
        }

        /// <summary>
        /// 初始化，生成空字段列表
        /// </summary>
        public DeduplicateRule()
        {
            _DeduplicateRuleFields = new List<DeduplicateRuleField>();
        }
    }
    /// <summary>
    /// 规则类型，Auto:如系统自动（规则定义比较严谨，无需人工再确认），Manua:人工确认
    /// </summary>
    public enum DeduplicateRuleType
    {
        Manual, Auto
    }

    /// <summary>
    /// 查重规则字段
    /// </summary>
    public class DeduplicateRuleField
    {
        /// <summary>
        /// 字段名称
        /// </summary>
        private string _fieldName;
       
        public string FieldName
        {
            get { return _fieldName; }
            set { _fieldName = value; }
        }

        /// <summary>
        /// 针对当前字段进行加工的函数列表
        /// </summary>
        private List<Littlebeer.Deduplicate.Models.DeduplicateFunction> _DeduplicateFunctions;

        public List<Littlebeer.Deduplicate.Models.DeduplicateFunction> DeduplicateFunctions
        {
            get { return _DeduplicateFunctions; }
            set { _DeduplicateFunctions = value; }
        }

        /// <summary>
        /// 初始化查重规则类，创建处理函数空列表
        /// </summary>
        public DeduplicateRuleField()
        {
            _DeduplicateFunctions = new List<DeduplicateFunction>();
        }

        /// <summary>
        /// 根据字段名创建无处理查重规则字段
        /// </summary>
        /// <param name="fieldName"></param>
        public DeduplicateRuleField(string fieldName)
        {
            _fieldName = fieldName;
            _DeduplicateFunctions = new List<DeduplicateFunction>() {new Deduplicate.Models.DeduplicateFunction(){ FunctionName="", DeduplicateFunctionType=Deduplicate.Models.DeduplicateFunctionType.Single, Orders=0, Args=new List<string>(){""}}};
        }

        /// <summary>
        /// 根据字段名和单一函数创建查重规则字段
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="function"></param>
        public DeduplicateRuleField(string fieldName,DeduplicateFunction function)
        {
            _fieldName = fieldName;
            _DeduplicateFunctions = new List<DeduplicateFunction>() {function};
        }

        /// <summary>
        /// 根据字段名和函数列表创建查重规则字段
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="functions"></param>
        public DeduplicateRuleField(string fieldName, List<DeduplicateFunction> functions)
        {
            //验证用户输入参数有效性
            if (functions == null || functions.Count() == 0)
            {
                throw (new Exception("请指定至少一个处理函数"));
            }

            _fieldName = fieldName;
            _DeduplicateFunctions = functions;
        }
    }

}
